package com.demo.controller;

import com.demo.feign.StockFeignClient;
import com.demo.rabbitmq.SmsProducer;
import com.demo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;



@RestController
@RequestMapping("/stock")
@RefreshScope //自动刷新配置
public class stockController {

    @Value("${config.info}")
    String name;
    @Autowired
    private StockFeignClient stockFeignClient;


    @Resource
    private SmsProducer smsProducer;
    @Resource
    private OrderService orderService;

    @GetMapping("/test")
    public String test(String info){
        return  name;
    }
    @RequestMapping(path = "/deduct")
    public Boolean deduct(String commodityCode, Integer count){
        stockFeignClient.deduct(commodityCode,count);
        return  true;
    }

    @GetMapping("/send")
    public void Send(String msg){
        smsProducer.sendMsg(msg);
    }


    @RequestMapping("/placeOrder/rollback")
    public Boolean placeOrderRollback(String userId, String commodityCode, Integer count) {
        // product-2 扣库存时模拟了一个业务异常,
        orderService.placeOrder(userId, commodityCode, count);
        return true;
    }

}

